

/**************************/
/**
 * 正则替换表情
 */
function replaceEmotion(text){
	text=text.replace(/<img.*?alt=["]{0,1}([^"\s]*).*?>/ig, "/$1").replace(/<br.*?>/ig, "\n").replace(/<.*?>/g, "").replace(/&amp;/gi, "&").replace(/&quot;/gi, '"').replace(/&nbsp;/gi, " ").replace(/&copy;/gi, "©").replace(/&reg;/gi, "®")
	return text;
}
/*** 计算字数***/
function getLength(str, shortUrl) {
			if (true == shortUrl) {
				// 一个URL当作十个字长度计算
				return Math.ceil(str.replace(/((news|telnet|nttp|file|http|ftp|https):\/\/){1}(([-A-Za-z0-9]+(\.[-A-Za-z0-9]+)*(\.[-A-Za-z]{2,5}))|([0-9]{1,3}(\.[0-9]{1,3}){3}))(:[0-9]*)?(\/[-A-Za-z0-9_\$\.\+\!\*\(\),;:@&=\?\/~\#\%]*)*/ig, 'xxxxxxxxxxxxxxxxxxxx')
									.replace(/^\s+|\s+$/ig,'').replace(/[^\x00-\xff]/ig,'xx').length/2);
			} else {
				return Math.ceil(str.replace(/^\s+|\s+$/ig,'').replace(/[^\x00-\xff]/ig,'xx').length/2);
			}
}
		
/***清空表单***/
function clearForm(id){
	$(':input','#'+id)
     .not(':button, :submit, :reset, :hidden')
     .val('')
     .removeAttr('checked')
     .removeAttr('selected');
}

/**
 * 替换当前url中的wid
 * @param obj
 */
function changeWeiChat(obj){
	var id=obj.value;
	//获取当前连接
	var url=window.location.href;
	if(url.indexOf('?')==-1){
		window.location.href=window.location.href+'?wid='+id;
	}else{
		//找到是否含有wid
		var reg=replaceParamVal('wid',id);
		window.location.href=reg;
	}
}
//替换指定传入参数的值,paramName为参数,replaceWith为新值
function replaceParamVal(paramName,replaceWith) {
    var oUrl = this.location.href.toString();
    var re=eval('/('+ paramName+'=)([^&]*)/gi');
    var nUrl = oUrl.replace(re,paramName+'='+replaceWith);
    return nUrl;
}

function checkDataGridRow(id){
	if($('#select_'+id).is(":checked")){
		$('#select_'+id).attr('checked',false);
	}else{
		$('#select_'+id).attr('checked',true);
	}
}

//全选
$(function(){
	$('.check_all').click(function(){
		if($(this).is(":checked")){
			$(":checkbox[name='SelectedID']").attr('checked',true);
		}else{
			$(":checkbox[name='SelectedID']").attr('checked',false);
		}
	});
	$(":checkbox[name='SelectedID']").click(function(e){
		e.stopPropagation();
		if($(this).is(":checked")){
			$(this).attr('checked',true);
		}else{
			$(this).attr('checked',false);
		}
	});
});
//批量删除和单个删除使用一个方法。
function batchDeleteFun(url,id,msg){
	if(msg==""||typeof(msg)=='undefined')msg="确认删除这些记录么？删除不可恢复，请慎重操作！";
	event.stopPropagation();
	//确认对话框
	var ids = [];
	if(id){
		ids.push(id);
	}else{
		//获取checkbox所选
		 $('input[name="SelectedID"]:checked').each(function(){ 
			 ids.push($(this).val());
	     }); 
	}
	if(ids.length==0){
		dialog({
		    title: '提示信息',
		    content:'请选择项目!',
		    ok: function () {}
		}).show();
		return;  
	}
	var d=dialog({
	    title: '确认提示',
	    content: msg,
	    okValue: '确定',
	    ok: function () {
	    	d.close().remove();
	    	$ .axs(url,'ids='+ids.join(","));
	    	return false;
	    },
	    cancelValue: '关闭',
	    cancel: true //为true等价于function(){}
	}).show();
	
}

//批量删除和单个删除使用一个方法。
function batchAudit(url,status,id){
	event.stopPropagation();
	//确认对话框
	var ids = [];
	if(id){
		ids.push(id);
	}else{
		//获取checkbox所选
		 $('input[name="SelectedID"]:checked').each(function(){ 
			 ids.push($(this).val());
	     }); 
	}
	if(ids.length==0){
		dialog({
		    title: '提示信息',
		    content:'请选择项目!',
		    ok: function () {}
		}).show();
		return;  
	}
	$ .axsf(url,'ids='+ids.join(",")+"&status="+status,function(d){
		if(d.code==200){
			window.location.reload();
		}
	});
}
